import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.standard.Copies;

public class Ausdrucken_IK {
	
	public Ausdrucken_IK(){
		super();
	}
	
	public static void main(String[] args){
		Ausdrucken_IK ausdrucken_IK = new Ausdrucken_IK();
		
		ausdrucken_IK.drucken();
	}
	
	private void drucken(){
		// Variablen deklarieren
		String pfadBild = "C:/Daten/Verpackungsanlage/Kameras/IK_alt/IK_1.bmp";

		File f = new File(pfadBild);

		if (f.exists()) {
			PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
			pras.add(new Copies(1));
			PrintService pss[] = PrintServiceLookup.lookupPrintServices(
					DocFlavor.INPUT_STREAM.GIF, pras);
			if (pss.length == 0)
				throw new RuntimeException("Kein Drucker installiert");
			
			// Zur Bestimmung des Druckers
			// Zahlen beginnend bei 0
	//		for (int i = 0; i < 10; i++) {
	//			if (pss[i] != null)
	//				System.out.println(pss[i]);
	//		}
			
			
			PrintService ps = pss[5];
			System.out.println("Drucken mit: " + ps);
			DocPrintJob job = ps.createPrintJob();
			FileInputStream fin = null;
			try {
				fin = new FileInputStream(pfadBild);
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null);
			try {
				job.print(doc, pras);
			} catch (PrintException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			try {
				fin.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}